package org.example.延迟消息.生产;

import lombok.SneakyThrows;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

/**
 * @Auther:Liu
 * @Testname:延迟消息发送
 * @Date:2025/8/22 18:58
 */
public class 延迟消息发送 {
    @SneakyThrows
    public static void main(String[] args) {
        DefaultMQProducer producer = new DefaultMQProducer("producer_group_b");
        producer.setNamesrvAddr("192.168.10.88:9876");
        producer.start();
       String topic = "topic_a";
       String tag = "yanchi";
       String body="时间发的";
       Message message = new Message(topic, tag, body.getBytes(StandardCharsets.UTF_8));
       message.setDelayTimeLevel(3);
       SendResult sendResult = producer.send(message);
       System.out.println(sendResult);
        producer.shutdown();
    }
}
